#!/usr/bin/env python

import json
from coin.exchange.bitfinex_v2.kr_rest.product import BitfinexProduct

from tornado import httpclient

cli = httpclient.HTTPClient()
res = cli.fetch('https://api.bitfinex.com/v1/symbols_details')
message = json.loads(res.body)

product_infos = {}
for item in message:
  '''
  {
      'expiration': 'NA',
      'initial_margin': '30.0',
      'margin': True,
      'maximum_order_size': '2000.0',
      'minimum_margin': '15.0',
      'minimum_order_size': '0.002',
      'pair': 'btcusd',
      'price_precision': 5
  }
  '''
  try:
    native_symbol_v1 = item['pair']
    key = BitfinexProduct.FromStrNativeProductV1(native_symbol_v1)
    tick_size = None
    step_size = None
    price_precision = item['price_precision']
    min_qty = float(item['minimum_order_size'])
    max_qty = float(item['maximum_order_size'])
    val = '%f, %f' % (min_qty, max_qty)
    product_infos[key] = (native_symbol_v1, val)
  except (ValueError, AssertionError):
    continue

for product in sorted(product_infos.keys()):
  _, pi_str = product_infos[product]
  native_symbol = product.native_symbol
  print('    \'%s\': _gen_product_info(%s),' % (native_symbol, pi_str))
